﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.ViewModels/ResultSummaryViewModel
* 类       名: ResultSummaryViewModel
* 功      能:  ResultSummaryView的Model类.
* 时      间:  2023/7/22 9:00:59
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using OfficeOpenXml.Drawing.Controls;
using SiliconSelect.Base;
using SiliconSelect.BLL;
using SiliconSelect.Common;
using SiliconSelect.DAL.DataEntity;
using SiliconSelect.Models;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;

namespace SiliconSelect.ViewModels
{
    public class ResultSummaryViewModel : NotifyBase
    {
        public ResultSummaryViewModel()
        {
            InitData(ShowLog: true);
            AsyncTaskStart();
            DataOperateCommand = new Command(DoDataOperateTask);
            PageOperaterCommand = new Command(DoPageOperateTask);
            ExportDir = GlobalValues.SummaryExportPath; // 从全局里拿到导出目录.
        }

        private int _singlePageCount = 1000; // 单独一页显示的数据个数

        // 分页操作任务
        private void DoPageOperateTask(object obj)
        {
            if (obj != null)
            {
                IsReresh = false;
                switch (obj.ToString())
                {
                    // 不管是上一页,还是下一页,还是固定页,先给页面刷新关闭.   
                    case "PrePage":
                        // 上一页
                        if (CurrentPage <= 1) return; // 当页面小于等于1时,就直接返回.
                        else
                        {
                            ResultSummaryPage.Clear();
                            for (int i = (CurrentPage - 2) * _singlePageCount; i < _singlePageCount + (CurrentPage - 2) * _singlePageCount; i++)
                            {
                                ResultSummaryPage.Add(ResultSummaryList[i]);
                            }
                            CurrentPage--;
                            CurrentPageCount = ResultSummaryPage.Count;
                        }
                        break;
                    case "NextPage":
                        // 下一页
                        if (CurrentPage >= TotalPage) return; // 如果是最后一页,直接返回
                        else
                        {
                            ResultSummaryPage.Clear();
                            int finalCountMax = Math.Min(CurrentPage * _singlePageCount + _singlePageCount, ResultSummaryList.Count);

                            for (int i = CurrentPage * _singlePageCount; i < finalCountMax; i++)
                            {
                                ResultSummaryPage.Add(ResultSummaryList[i]);
                            }
                            ++CurrentPage;
                            CurrentPageCount = ResultSummaryPage.Count;
                        }
                        break;
                    case "GoForward":
                        // 跳转指定页面
                        int number;
                        bool res = int.TryParse(CurrentPageShow, out number);
                        if (res)
                        {
                            // 如果成功了
                            if (number > TotalPage)
                            {
                                CurrentPage = TotalPage;
                            }
                            else if (number <= 1)
                            {
                                CurrentPage = 1;
                            }
                            else
                            {
                                CurrentPage = number;
                            }

                            ResultSummaryPage.Clear();
                            int finalCountMax = Math.Min((CurrentPage - 1) * _singlePageCount + _singlePageCount, ResultSummaryList.Count);

                            for (int i = (CurrentPage - 1) * _singlePageCount; i < finalCountMax; i++)
                            {
                                ResultSummaryPage.Add(ResultSummaryList[i]);
                            }
                            CurrentPageCount = ResultSummaryPage.Count;

                        }
                        else
                        {
                            MessageBox.Show("输入格式错误,请输入正确的数字!", "数据输入格式错误提示框", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        break;
                    default:
                        break;
                }
            }
        }


        public Command PageOperaterCommand { get; set; }


        // 当前页
        private int _currentPage = 1;
        // 所有页
        private int _totalPage;
        // 当前页数据总个数
        private int _currentPageCount;
        // 所有页数据总数
        private int _totalPageCount;



        public int CurrentPage
        {
            get { return _currentPage; }
            set
            {
                CurrentPageShow = $"{value} / {TotalPage}";
                SetProperty(ref _currentPage, value);
            }
        }


        public int TotalPage
        {
            get { return _totalPage; }
            set { SetProperty(ref _totalPage, value); }
        }


        public int CurrentPageCount
        {
            get { return _currentPageCount; }
            set { SetProperty(ref _currentPageCount, value); }
        }


        public int TotalPageCount
        {
            get { return _totalPageCount; }
            set { SetProperty(ref _totalPageCount, value); }
        }

        // 用来显示当前多少页,主要用来显示总页数和分页数
        private string? _currentPageShow;

        public string? CurrentPageShow
        {
            get { return _currentPageShow; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    IsReresh = false;
                }
                SetProperty(ref _currentPageShow, value);
            }
        }


        // 保存结果汇总的集合(总记录)
        private ObservableCollection<WaferDetectedDetailModel> _resultSummaryList =
            new ObservableCollection<WaferDetectedDetailModel>();

        public ObservableCollection<WaferDetectedDetailModel> ResultSummaryList
        {
            get { return _resultSummaryList; }
            set { SetProperty(ref _resultSummaryList, value); }
        }

        // 分页记录
        private ObservableCollection<WaferDetectedDetailModel> _resultSummaryPage =
            new ObservableCollection<WaferDetectedDetailModel>();

        public ObservableCollection<WaferDetectedDetailModel> ResultSummaryPage
        {
            get { return _resultSummaryPage; }
            set { SetProperty(ref _resultSummaryPage, value); }
        }





        /// <summary>
        /// 显示操作成功,默认隐藏
        /// </summary>
        private string hintVisible = "Collapsed";

        public string HintVisible
        {
            get { return hintVisible; }
            set { SetProperty(ref hintVisible, value); }
        }

        /// <summary>
        /// 提示内容
        /// </summary>
        private string? _hintContent;

        public string? HintContent
        {
            get { return _hintContent; }
            set { SetProperty(ref _hintContent, value); }
        }



        /// <summary>
        /// 数据操作命令
        /// </summary>
        public Command DataOperateCommand { get; set; }
        private void DoDataOperateTask(object obj)
        {
            if (obj != null)
            {
                switch (obj.ToString())
                {
                    case "Query":
                        // 查询操作
                        QueryDataByInput();
                        break;
                    case "Export":
                        ExportDataByInput();
                        break;
                    case "OpenExport":
                        OpenExportDir();
                        break;
                    case "OpenSummary":
                        OpenSummaryDir();
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 打开汇总目录,按照日期的那个目录去搞定
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        private void OpenSummaryDir()
        {
            string openDir = Path.GetDirectoryName(GlobalValues.SummaryByDayPath)!;
            string fileNameSelectd = Path.GetFileName(GlobalValues.SummaryByDayPath);
            if (Directory.Exists(openDir))
            {
                if (File.Exists(GlobalValues.SummaryByDayPath))
                {
                    Process.Start("Explorer", "/select," + openDir + "\\" + fileNameSelectd);
                }
                else
                {
                    // 先获取所有的文件名
                    FileInfo[] files = new DirectoryInfo(openDir).GetFiles();
                    Array.Sort(files, delegate (FileInfo x, FileInfo y) { return y.CreationTime.CompareTo(x.CreationTime); });
                    string fileSelected = files[0].Name;

                    Process.Start("Explorer", "/select," + openDir + "\\" + fileSelected);
                }
            }
        }


        /// <summary>
        /// 打开导出目录.
        /// </summary>
        private void OpenExportDir()
        {
            if (Directory.Exists(ExportDir))
            {
                string writePath;
                if (string.IsNullOrEmpty(CrystalNameInput))
                {
                    writePath = Path.Combine(ExportDir!, $"KY02_{GlobalValues.CrystalNumberCurrent!}.csv");
                }
                else
                {
                    writePath = Path.Combine(ExportDir!, $"KY02_{CrystalNameInput}.csv");
                }
                if (File.Exists(writePath))
                {
                    Process.Start("Explorer", "/select," + ExportDir + "\\" + Path.GetFileName(writePath));
                }
                else
                {
                    // 先获取所有的文件名
                    FileInfo[] files = new DirectoryInfo(ExportDir).GetFiles();
                    if (files.Length > 0)
                    {
                        Array.Sort(files, delegate (FileInfo x, FileInfo y) { return y.CreationTime.CompareTo(x.CreationTime); });
                        string fileSelected = files[0].Name;
                        Process.Start("Explorer", "/select," + ExportDir + "\\" + fileSelected);
                    }
                    else
                    {
                        Process.Start("Explorer", ExportDir);
                    }
                }
            }
        }


        private void ExportDataByInput()
        {
            string writePath;
            string crystalName;
            if (string.IsNullOrEmpty(CrystalNameInput))
            {
                writePath = Path.Combine(ExportDir!, $"KY02_{GlobalValues.CrystalNumberCurrent!}.csv");
                crystalName = GlobalValues.CrystalNumberCurrent!;
            }
            else
            {
                writePath = Path.Combine(ExportDir!, $"KY02_{CrystalNameInput}.csv");
                crystalName = CrystalNameInput;
            }


            Task.Run(async () =>
            {
                Stopwatch stt = new Stopwatch();
                stt.Start();
                FileOperateHelper.CreateAnEmptyFile(writePath);
                CsvHelper.WriteToCsvSingleLine(writePath, GlobalValues.SummaryTitle);
                DataResult res;
                if (ExportDataTable != null)
                {
                    res = CsvHelper.DataTableToCsv(ExportDataTable!, writePath);
                    HintVisible = "Visible"; // 是否显示
                    if (!res.State)
                    {
                        HintContent = $"导出失败:{res.Message}";
                        LogHelper.WriteLog(LogType.Exception, $"写入失败: {res.Message}");
                    }
                    else
                    {
                        HintContent = "导出成功!";
                    }
                    stt.Stop();
                    LogHelper.WriteLog(LogType.Info, $"数据写入耗时{stt.Elapsed.TotalMilliseconds}");
                    await Task.Delay(2000);
                    HintContent = "";
                    HintVisible = "Collapsed";
                }
                else
                {
                    HintVisible = "Visible"; // 是否显示
                    HintContent = $"导出失败:无相关数据";
                    await Task.Delay(2000);
                    HintContent = "";
                    HintVisible = "Collapsed";
                }
            });

        }

        /// <summary>
        /// 根据输入去做查询.
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        private void QueryDataByInput()
        {
            IsReresh = false; // 实时刷新先关闭.
            string crystalNameUsed = string.IsNullOrEmpty(CrystalNameInput) ? GlobalValues.CrystalNumberCurrent! : CrystalNameInput;
            List<string> queryFiedls = new List<string> { };
            List<string> queryVals = new List<string> { };
            if (IsByWaferId && !string.IsNullOrEmpty(WaferIdInput))
            {
                queryFiedls.Add("WaferId");
                queryVals.Add(WaferIdInput!);
            }
            if (IsByLevel && !string.IsNullOrEmpty(DetectedLevelInput))
            {
                queryFiedls.Add("DetectedLevel");
                queryVals.Add(DetectedLevelInput!);
            }
            DataResult<List<WaferDetectedDetailEntity>> result = LocalDataAccess.GetResultSummaryByCondition(crystalNameUsed, queryFiedls, queryVals, isDesc: false);
            if (result.State)
            {
                DataRefreshSummary(result.Data!);
            }
            DataResult<DataTable> searchResDataTableRes = LocalDataAccess.GetDatatableResultSummaryByCrystal(crystalNameUsed, queryFiedls, queryVals, isDesc: false);
            if (result.State && searchResDataTableRes.Data != null && searchResDataTableRes.Data!.Rows.Count > 0)
            {
                ExportDataTable = searchResDataTableRes.Data!; // 赋值给搜索的Table
            }
        }

        public DataTable? ExportDataTable { get; set; }

        /// <summary>
        /// 导出目录
        /// </summary>
        private string? _exportDir;

        public string? ExportDir
        {
            get { return _exportDir; }
            set { _exportDir = value; }
        }


        /// <summary>
        /// 输入的流水号
        /// </summary>
        private string? _waferIdInput;

        public string? WaferIdInput
        {
            get { return _waferIdInput; }
            set { SetProperty(ref _waferIdInput, value); }
        }


        /// <summary>
        /// 输入的检测等级
        /// </summary>
        private string? _detectedLevelInput;

        public string? DetectedLevelInput
        {
            get { return _detectedLevelInput; }
            set { SetProperty(ref _detectedLevelInput, value); }
        }


        /// <summary>
        /// 根据晶棒编号是否选中,默认是选中装填.
        /// </summary>
        private bool _isByCrystalNumber = true;

        public bool IsByCrystalNumber
        {
            get { return _isByCrystalNumber; }
            set { SetProperty(ref _isByCrystalNumber, value); }
        }

        /// <summary>
        /// 按流水号是否选中
        /// </summary>
        private bool _isByWaferId;

        public bool IsByWaferId
        {
            get { return _isByWaferId; }
            set { SetProperty(ref _isByWaferId, value); }
        }


        /// <summary>
        /// 按等级
        /// </summary>
        private bool _isByLevel;

        public bool IsByLevel
        {
            get { return _isByLevel; }
            set { SetProperty(ref _isByLevel, value); }
        }




        /// <summary>
        /// 统计的所有晶棒编号的名称.
        /// </summary>
        private ObservableCollection<string> _crystalNames = new ObservableCollection<string>();

        public ObservableCollection<string> CrystalNames
        {
            get { return _crystalNames; }
            set { SetProperty(ref _crystalNames, value); }
        }


        /// <summary>
        /// 模糊查询查找的满足结果的晶棒编号.
        /// </summary>
        private ObservableCollection<string> _searchRes = new ObservableCollection<string>();

        public ObservableCollection<string> SearchRes
        {
            get { return _searchRes; }
            set { SetProperty(ref _searchRes, value); }
        }

        /// <summary>
        /// 是否显示搜索列表内容
        /// </summary>
        private string? _isShowSearchList = "Collapsed";

        public string? IsShowSearchList
        {
            get { return _isShowSearchList; }
            set { SetProperty(ref _isShowSearchList, value); }
        }

        /// <summary>
        /// 下拉菜单默认选中的项的索引
        /// </summary>
        private int _selectedIndex;

        public int SelectedIndex
        {
            get { return _selectedIndex; }
            set { SetProperty(ref _selectedIndex, value); }
        }

        /// <summary>
        /// 选中项
        /// </summary>
        private string? _selectedItem;

        public string? SelectedItem
        {
            get { return _selectedItem; }
            set { SetProperty(ref _selectedItem, value); }
        }



        /// <summary>
        /// 输入框宽度
        /// </summary>
        private int _boxInputWidth;

        public int BoxInputWIdth
        {
            get { return _boxInputWidth; }
            set { SetProperty(ref _boxInputWidth, value); }
        }

        private string? _crystalNameInput;

        public string? CrystalNameInput
        {
            get { return _crystalNameInput; }
            set { SetProperty(ref _crystalNameInput, value); }
        }



        private async void AsyncTaskStart()
        {
            // 1.  启动数据监控线程
            Task taskUpdate = RefreshDataAsync();
            await Task.WhenAll(taskUpdate);
        }

        /// <summary>
        /// 是否刷新界面.
        /// </summary>
        private bool _isRefresh = true;

        public bool IsReresh
        {
            get { return _isRefresh; }
            set
            {
                if (value)
                {
                    if (!IsReresh)
                    {
                        SetProperty(ref _isRefresh, value);
                        // 开启任务
                        AsyncTaskStart();
                    }
                }
                SetProperty(ref _isRefresh, value);
            }
        }


        private async Task RefreshDataAsync()
        {
            while (IsReresh)
            {
                await Task.Delay(1000);
                InitData();
                await Task.Delay(1000);
            }
        }


        // 数据初始化,数据刷新的时候调用
        public void InitData(bool ShowLog = false)
        {
            Stopwatch st = new Stopwatch();

            // 开始计时,默认刷新的是当前的晶棒编号的数据.
            st.Start();
            var resultSummaryResult = LocalDataAccess.GetResultSummary(GlobalValues.CrystalNumberCurrent!, isDesc: true);
            if (!resultSummaryResult.State)
            {
                LogHelper.WriteLog(LogType.Fatal, resultSummaryResult.Message);
                MessageBox.Show(resultSummaryResult.Message);
                Application.Current?.Shutdown();
                return;
            }
            DataRefreshSummary(resultSummaryResult.Data);
            DataResult<DataTable> searchResDataTableRes = LocalDataAccess.GetDatatableResultSummaryByCrystal(GlobalValues.CrystalNumberCurrent!, new List<string>(), new List<string>(), isDesc: false);
            if (searchResDataTableRes.State && searchResDataTableRes.Data != null && searchResDataTableRes.Data!.Rows.Count > 0)
            {
                ExportDataTable = searchResDataTableRes.Data!; // 赋值给搜索的Table
            }

            DataResult<List<string>> cystalNamesResult = LocalDataAccess.GetTotalCrystalNamesByRecordTb();
            if (!cystalNamesResult.State)
            {
                LogHelper.WriteLog(LogType.Exception, cystalNamesResult.Message);
                MessageBox.Show(cystalNamesResult.Message);
                Application.Current?.Shutdown();
                return;
            }
            DataRefreshCrystalResult(cystalNamesResult.Data!);
            st.Stop();
            //TimeSpan elapsedTime = st.Elapsed;
            if (ShowLog)
            {
                LogHelper.WriteLog(LogType.Info, $"详情页数据加载耗时: {st.ElapsedMilliseconds} ms");
            }
        }

        private void DataRefreshCrystalResult(List<string> list)
        {
            CrystalNames.Clear();
            foreach (string name in list)
            {
                CrystalNames.Add(name);
            }
        }


        private void DataRefreshSummary(List<WaferDetectedDetailEntity>? resultData)
        {
            ResultSummaryList.Clear();
            if (resultData != null && resultData.Count > 0)
            {
                foreach (var result in resultData!)
                {
                    WaferDetectedDetailModel model = new WaferDetectedDetailModel()
                    {
                        DetectedTime = result.DetectedTime,
                        ProductionDate = result.ProductionDate,
                        WaferId = result.WaferId,
                        CutNumber = result.CutNumber,
                        CrystalNumber = result.CrystalNumber,
                        PositionNumber = result.PositionNumber,
                        ProductionLot = result.ProductionLot,
                        FlowerNumber = result.FlowerNumber,
                        DetectionRecipe = result.DetectionRecipe,
                        DetectedLevel = result.DetectedLevel,
                        LevelType = result.LevelType,
                        TypeDescription = result.TypeDescription,
                        BoxNumber = result.BoxNumber,
                        ThicknessAver = result.ThicknessAver,
                        TTV = result.TTV,
                        LineTraceMax = result.LineTraceMax,
                        Warping = result.Warping,
                        ThicknessMin = result.ThicknessMin,
                        ThicknessMax = result.ThicknessMax,
                        IsDenseLine = result.IsDenseLine,
                        LineTraceUpNum = result.LineTraceUpNum,
                        LineTraceUpMax = result.LineTraceUpMax,
                        LineTraceDownNum = result.LineTraceDownNum,
                        LineTraceDownMax = result.LineTraceDownMax,
                        LineTraceCount = result.LineTraceCount,
                        ResistivityAver = result.ResistivityAver,
                        ResistivityMax = result.ResistivityMax,
                        ResistivityMin = result.ResistivityMin,
                        LengthMax = result.LengthMax,
                        LengthMin = result.LengthMin,
                        LengthX = result.LengthX,
                        LengthY = result.LengthY,
                        DiagonalLeftStart = result.DiagonalLeftStart,
                        DialonalRightStart = result.DialonalRightStart,
                        ChamferMax = result.ChamferMax,
                        ChamferMin = result.ChamferMin,
                        UpDownParallel = result.UpDownParallel,
                        LeftRightParallel = result.LeftRightParallel,
                        SquareLineMax = result.SquareLineMax,
                        SquareLineMin = result.SquareLineMin,
                        VerticalAngleMax = result.VerticalAngleMax,
                        VerticalAngleMin = result.VerticalAngleMin,
                        LeftTopCharmfer = result.LeftTopCharmfer,
                        RightTopCharmfer = result.RightTopCharmfer,
                        LeftBottomCharmfer = result.LeftBottomCharmfer,
                        RightBottomCharmfer = result.RightBottomCharmfer,
                        LeftTopAngle = result.LeftTopAngle,
                        RightTopAngle = result.RightTopAngle,
                        LeftBottomAngle = result.LeftBottomAngle,
                        RightBottomAngle = result.RightBottomAngle,
                        LengthXMax = result.LengthXMax,
                        LengthXMin = result.LengthXMin,
                        LengthYMax = result.LengthYMax,
                        LengthYMin = result.LengthYMin,

                        FrontEdgeBreakExist = result.FrontEdgeBreakExist,
                        FrontEdgeBreakNum = result.FrontEdgeBreakNum,
                        FrontEdgeBreakArea = result.FrontEdgeBreakArea,
                        BackEdgeBreakExist = result.BackEdgeBreakExist,
                        BackEdgeBreakNum = result.BackEdgeBreakNum,
                        BackEdgeBreakArea = result.BackEdgeBreakArea,
                        LeftEdgeBreakExist = result.LeftEdgeBreakExist,
                        LeftEdgeBreakNum = result.LeftEdgeBreakNum,
                        LeftSurfaceBreakNum = result.LeftSurfaceBreakNum,
                        LeftSurfaceBreakExist = result.LeftSurfaceBreakExist,
                        RightEdgeBreakExist = result.RightEdgeBreakExist,
                        RightEdgeBreakNum = result.RightEdgeBreakNum,
                        RightSurfaceBreakExist = result.RightSurfaceBreakExist,
                        RightSurfaceBreakNum = result.RightSurfaceBreakNum,
                        SumdgeUpExist = result.SumdgeUpExist,
                        SmudgeUpArea = result.SmudgeUpArea,
                        SumdgeUpNum = result.SumdgeUpNum,
                        SumdgeUpReverse = result.SumdgeUpReverse,
                        SumdgeUpHoleExist = result.SumdgeUpHoleExist,
                        SumdgeUpHoleNum = result.SumdgeUpHoleNum,
                        HoleExistUp = result.HoleExistUp,
                        HoleNumUp = result.HoleNumUp,
                        SumdgeDownExist = result.SumdgeDownExist,
                        SumdgeDownArea = result.SumdgeDownArea,
                        SumdgeDownNum = result.HoleNumDown,
                        SumdgeDownReverse = result.SumdgeDownReverse,
                        SumdgeDownHoleExist = result.SumdgeDownHoleExist,
                        SumdgeDownHoleNum = result.SumdgeDownHoleNum,
                        HoleExistDown = result.HoleExistDown,
                        HoleNumDown = result.HoleNumDown,
                        SubfissureArea01 = result.SubfissureArea01,
                        SubfissureNum01 = result.SubfissureNum01,
                        SubfissureExist01 = result.SubfissureExist01,
                        SubfissureBreakArea01 = result.SubfissureBreakArea01,
                        SubfissureBreakNum01 = result.SubfissureBreakNum01,
                        SubfissureBreakExist01 = result.SubfissureBreakExist01,
                        SubfissureHoleNum01 = result.SubfissureHoleNum01,
                        SubfissureHoleExist01 = result.SubfissureHoleExist01,
                        SubfissureArea02 = result.SubfissureArea02,
                        SubfissureNum02 = result.SubfissureNum02,
                        SubfissureExist02 = result.SubfissureExist02,
                        SubfissureBreakArea02 = result.SubfissureBreakArea02,
                        SubfissureBreakNum02 = result.SubfissureBreakNum02,
                        SubfissureBreakExist02 = result.SubfissureBreakExist02,
                        SubfissureHoleNum02 = result.SubfissureHoleNum02,
                        SubfissureHoleExist02 = result.SubfissureHoleExist02,
                    };
                    ResultSummaryList.Add(model);
                }

                ResultSummaryPage.Clear();
                // 每次数据更新的时候,分页信息也要更新一下.
                TotalPage = ResultSummaryList.Count / _singlePageCount + (ResultSummaryList.Count % _singlePageCount == 0 ? 0 : 1);
                // 如果只有一页
                if (TotalPage <= 1)
                {
                    foreach (var model in ResultSummaryList)
                    {
                        ResultSummaryPage.Add(model);
                    }
                }
                else
                {
                    for (int i = 0; i < _singlePageCount; i++)
                    {
                        ResultSummaryPage.Add(ResultSummaryList[i]);
                    }
                }
                CurrentPageCount = ResultSummaryPage.Count;
                TotalPageCount = ResultSummaryList.Count;
                CurrentPage = 1;
            }
            else
            {
                ResultSummaryPage.Clear();
                TotalPage = 1;
                CurrentPage = 1;
                CurrentPageCount = 0;
                TotalPageCount = 0;
            }
        }
    }
}
